//
//  HomeCell5.m
//  Tunnel
//
//  Created by wbb on 2025/6/3.
//

#import "HomeCell5.h"
#import "JKGJVC.h"
#import "GZGJVC.h"
#import "JKGJDetailVC.h"
#import "GZGJDetailVC.h"
@implementation HomeCell5

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.title1.text = @"";
    self.detailLab1.text = @"";
    
    self.title2.text = @"";
    self.detailLab2.text = @"";
    
    self.title3.text = @"";
    self.detailLab3.text = @"";
    
    self.tipLab.text  = @"共有 0 个 设备告警中";

    self.currentType = 0;
    
    UIImageView *lineImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gjtj_tab_icon"]];
    [self.bottomView addSubview:lineImgView];
    self.lineImgView = lineImgView;
    [lineImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.jkgjBtn.mas_bottom).offset(0);
        make.centerX.equalTo(self.jkgjBtn.mas_centerX);
        
    }];
    
    
    [self.stack1 addTarget:self action:@selector(onRowClick1)];
    [self.stack2 addTarget:self action:@selector(onRowClick2)];
    [self.stack3 addTarget:self action:@selector(onRowClick3)];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)loadMore:(id)sender {
    if(self.currentType == 0) {
        JKGJVC *vc = [[JKGJVC alloc] init];
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else {
        GZGJVC *vc = [[GZGJVC alloc] init];
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
}

- (IBAction)tabClick:(UIButton *)sender {
    [self.lineImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.jkgjBtn.mas_bottom).offset(0);
        make.centerX.equalTo(sender.mas_centerX);
    }];
    
    if(sender == self.gzgjBtn ){
        NSArray *faultDeviceList = [NSArray arrayWithArray:self.dataDic[@"faultDeviceList"]];
        [self dataWithArr:faultDeviceList andNum:[self.dataDic[@"faultNum"]?:@"0" integerValue]];
        self.currentType = 1;
    }else {
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"alarmDeviceList"]];
        [self dataWithArr:alarmDeviceList andNum:[self.dataDic[@"alarmNum"]?:@"0" integerValue]];
        self.currentType = 0;
    }
}

- (void)cellWithData:(id)data {
    [super cellWithData:data];
    if(!data) return;
    NSDictionary *dic = (NSDictionary *)data;
    self.dataDic = dic;
//    self.sbzsLab.text = kAppStringFormat(@"%@", dic[@"total"]?:@"") ;
//    self.gjsbLab.text = kAppStringFormat(@"%@", dic[@"alarmNum"]?:@"");
//    self.lxsbLab.text = kAppStringFormat(@"%@", dic[@"offLineNum"]?:@"");
//    self.gzsbLab.text = kAppStringFormat(@"%@", dic[@"faultNum"]?:@"");
    
    NSArray *alarmDeviceList = [NSArray arrayWithArray:dic[@"alarmDeviceList"]];
    [self dataWithArr:alarmDeviceList andNum:[dic[@"alarmNum"]?:@"0" integerValue]];

}


- (void)dataWithArr:(NSArray *)alarmDeviceList andNum:(NSInteger)num {
    self.tipLab.text  = [NSString stringWithFormat:@"共有 %ld 个 设备告警中",(long)num];
    self.stack1.hidden = YES;
    self.stack2.hidden = YES;
    self.stack3.hidden = YES;
    self.tipLab1.hidden = YES;
    if(alarmDeviceList.count == 1){
        NSDictionary *alarmDevice1 =alarmDeviceList[0];
        self.title1.text = [NSString stringWithFormat:@"%@・%@%@・%@",alarmDevice1[@"direction"],alarmDevice1[@"devName"],alarmDevice1[@"pileNo"],alarmDevice1[@"id"]];
        self.detailLab1.text = [NSString stringWithFormat:@"%@",alarmDevice1[@"cause"]];
        self.stack1.hidden = NO;

    }else if(alarmDeviceList.count == 2){
        NSDictionary *alarmDevice1 =alarmDeviceList[0];
        self.title1.text = [NSString stringWithFormat:@"%@・%@%@・%@",alarmDevice1[@"direction"],alarmDevice1[@"devName"],alarmDevice1[@"pileNo"],alarmDevice1[@"id"]];
        self.detailLab1.text = [NSString stringWithFormat:@"%@",alarmDevice1[@"cause"]];
        
        NSDictionary *alarmDevice2 =alarmDeviceList[1];
        self.title2.text = [NSString stringWithFormat:@"%@・%@%@・%@",alarmDevice2[@"direction"],alarmDevice2[@"devName"],alarmDevice2[@"pileNo"],alarmDevice2[@"id"]];
        self.detailLab2.text = [NSString stringWithFormat:@"%@",alarmDevice2[@"cause"]];
        self.stack1.hidden = NO;
        self.stack2.hidden = NO;
    }else if(alarmDeviceList.count >= 3){
        NSDictionary *alarmDevice1 =alarmDeviceList[0];
        self.title1.text = [NSString stringWithFormat:@"%@・%@%@・%@",alarmDevice1[@"direction"],alarmDevice1[@"devName"],alarmDevice1[@"pileNo"],alarmDevice1[@"id"]];
        self.detailLab1.text = [NSString stringWithFormat:@"%@",alarmDevice1[@"cause"]];
        
        NSDictionary *alarmDevice2 =alarmDeviceList[1];
        self.title2.text = [NSString stringWithFormat:@"%@・%@%@・%@",alarmDevice2[@"direction"],alarmDevice2[@"devName"],alarmDevice2[@"pileNo"],alarmDevice2[@"id"]];
        self.detailLab2.text = [NSString stringWithFormat:@"%@",alarmDevice2[@"cause"]];
        
        NSDictionary *alarmDevice3 =alarmDeviceList[2];
        self.title3.text = [NSString stringWithFormat:@"%@・%@%@・%@",alarmDevice3[@"direction"],alarmDevice3[@"devName"],alarmDevice3[@"pileNo"],alarmDevice3[@"id"]];
        self.detailLab3.text = [NSString stringWithFormat:@"%@",alarmDevice3[@"cause"]];
        
        self.stack1.hidden = NO;
        self.stack2.hidden = NO;
        self.stack3.hidden = NO;
    }else {
        self.tipLab1.hidden = NO;
    }
}

- (void)onRowClick1 {
    if(self.currentType == 0){
        // 监控告警详情
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"alarmDeviceList"]];
        NSDictionary *alarmDevice1 =alarmDeviceList[0];
//        if(self.callBack){
//            self.callBack(alarmDevice1);
//        }
        JKGJDetailVC * vc = [JKGJDetailVC new];
        vc.jkId = alarmDevice1[@"alarmId"];
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else {
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"faultDeviceList"]];
        NSDictionary *alarmDevice1 =alarmDeviceList[0];
        GZGJDetailVC * vc = [GZGJDetailVC new];
        vc.gjId = alarmDevice1[@"alarmId"];
        vc.lx = alarmDevice1[@"lx"];
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
}
- (void)onRowClick2 {
    if(self.currentType == 0){
        // 监控告警详情
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"alarmDeviceList"]];
        NSDictionary *alarmDevice1 =alarmDeviceList[1];
//        if(self.callBack){
//            self.callBack(alarmDevice1);
//        }
        JKGJDetailVC * vc = [JKGJDetailVC new];
        vc.jkId = alarmDevice1[@"alarmId"];
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else {
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"faultDeviceList"]];
        NSDictionary *alarmDevice1 =alarmDeviceList[1];
        GZGJDetailVC * vc = [GZGJDetailVC new];
        vc.gjId = alarmDevice1[@"alarmId"]?:@"";
        vc.lx = alarmDevice1[@"lx"]?:@"";
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
}
- (void)onRowClick3 {
    if(self.currentType == 0){
        // 监控告警详情
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"alarmDeviceList"]];
        NSDictionary *alarmDevice1 =alarmDeviceList[2];
//        if(self.callBack){
//            self.callBack(alarmDevice1);
//        }
        JKGJDetailVC * vc = [JKGJDetailVC new];
        vc.jkId = alarmDevice1[@"alarmId"];
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }else {
        NSArray *alarmDeviceList = [NSArray arrayWithArray:self.dataDic[@"faultDeviceList"]];
        NSDictionary *alarmDevice1 =alarmDeviceList[2];
        GZGJDetailVC * vc = [GZGJDetailVC new];
        vc.gjId = alarmDevice1[@"alarmId"];
        vc.lx = @"1";
        [[WDGlobal getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
}
@end
